clear all
set more off , permanently
capture log close
set scheme s1color
graph set window fontface "Garamond"
set type double

*******************************************************************
********** This file prepares data for SDID analysis **************
*******************************************************************


******************************************************************
** Load Germany-France panel: merge with distance to the border **
******************************************************************

	** Load distance to France-German border: stations in Germany
		use "$dta\stations_dist_to_border.dta" , clear					 
		keep if id_data != ""
		keep id_data km_to_french_border
		rename id_data station_id 
		gen country="de"
		cd "$dta"
		save ger_border.dta , replace	

	** Load distance to France-German border: stations in France 									 
		use "$dta\stations_dist_to_border.dta" , clear
		keep if id_pdv != .
		tostring id_pdv, gen(station_id)
		keep station_id km_to_french_border
		gen country="fr"
		cd "$dta"
		save fr_border.dta , replace
		
		
	// Load Germany-France price panel 	
		cd "$dta"
		use germany_france.dta , clear

	* Merge with distance to border: France
		merge m:1 station_id country using ger_border.dta									 
		drop if _m == 2
		drop _m 
		rename km_to_french_border km_to_french_border_de
		erase ger_border.dta
		
	* Merge with distance to border: France
		merge m:1 station_id country using fr_border.dta									 
		drop if _m == 2
		drop _m	
		erase fr_border.dta 
		
	* Gen distance to border 
		replace km_to_french_border = km_to_french_border_de if country=="de"
		drop km_to_french_border_de
		
	* Save 
		save "$dta\germany_france_border", replace

		
	eststo clear		
	
	
		
//////////////////////////////////
////////// FULL COUNTRY //////////		
//////////////////////////////////

	
************************************************************
*****   Prepare data for estimation with SDID: petrol  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
	
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace e5_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_e5 = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if e5_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		replace wavg_price_e5 = wavg_price_e5 * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel p_rotterdam e5_margin_17oclock wavg_price_e5, by(id week week_n country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		gen log_p_wavg = log(wavg_price_e5)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap)
		local e5_5pm_sdid_all_coef = e(ATT)
		local e5_5pm_sdid_all_se = e(se)
		
		sdid log_p_wavg id week treated , vce(bootstrap)
		local e5_wavg_sdid_all_coef = e(ATT)
		local e5_wavg_sdid_all_se = e(se)
		
		sdid log_p_5pm id week treated , covariates(de_brent) vce(bootstrap)
		local e5_5pm_sdid_all_crude_coef = e(ATT)
		local e5_5pm_sdid_all_crude_se = e(se)

		sdid e5_margin_17oclock id week treated , vce(bootstrap)
		local e5_margin_sdid_all_coef = e(ATT)
		local e5_margin_sdid_all_se = e(se)
		
		local nr_obs_e5_sdid_all = _N
		
		sum e5_margin_17oclock if country == "de" & treatment_period == 0
		local margin_e5_all = r(mean)

		

************************************************************
*****   Prepare data for estimation with SDID: diesel  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
	
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace gazole_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_gazole = . if date > d(12sep2013) & date < d(01oct2013)
		
	* Drop if missing margin (missing price <-> missing margin)
		drop if gazole_margin_17oclock == .
			

	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		replace wavg_price_gazole = wavg_price_gazole * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel p_rotterdam gazole_margin_17oclock wavg_price_gazole, by(id week week_n country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		gen log_p_wavg = log(wavg_price_gazole)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_5pm_sdid_all_coef = e(ATT)
		local diesel_5pm_sdid_all_se = e(se)
		
		sdid log_p_wavg id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_wavg_sdid_all_coef = e(ATT)
		local diesel_wavg_sdid_all_se = e(se)
		
		sdid log_p_5pm id week treated , covariates(de_brent) vce(bootstrap)
		local diesel_5pm_sdid_all_crude_coef = e(ATT)
		local diesel_5pm_sdid_all_crude_se = e(se)

		sdid gazole_margin_17oclock id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_margin_sdid_all_coef = e(ATT)
		local diesel_margin_sdid_all_se = e(se)
		
		local nr_obs_diesel_sdid_all = _N
		
		sum gazole_margin_17oclock if country == "de" & treatment_period == 0
		local margin_diesel_all = r(mean)		
		
	
	

		
		
		
////////////////////////////////////////////////////////////
////////// 20 to 100 km from Franco-German border //////////		
////////////////////////////////////////////////////////////

	
************************************************************
*****   Prepare data for estimation with SDID: petrol  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 100km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 100		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace e5_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_e5 = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if e5_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		replace wavg_price_e5 = wavg_price_e5 * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel p_rotterdam e5_margin_17oclock wavg_price_e5, by(id week week_n country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		gen log_p_wavg = log(wavg_price_e5)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local e5_5pm_sdid_20to100_coef = e(ATT)
		local e5_5pm_sdid_20to100_se = e(se)
		
		sdid log_p_wavg id week treated , vce(bootstrap) reps(200) seed(10)
		local e5_wavg_sdid_20to100_coef = e(ATT)
		local e5_wavg_sdid_20to100_se = e(se)
		
		sdid log_p_5pm id week treated , covariates(de_brent) vce(bootstrap) reps(200) seed(10)
		local e5_5pm_sdid_20to100_crude_coef = e(ATT)
		local e5_5pm_sdid_20to100_crude_se = e(se)

		sdid e5_margin_17oclock id week treated , vce(bootstrap) reps(200) seed(10)
		local e5_margin_sdid_20to100_coef = e(ATT)
		local e5_margin_sdid_20to100_se = e(se)
		
		local nr_obs_e5_sdid_20to100 = _N
		
		sum e5_margin_17oclock if country == "de" & treatment_period == 0
		local margin_e5_20to100 = r(mean)		
		


************************************************************
*****   Prepare data for estimation with SDID: diesel  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 100km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 100		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace gazole_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_gazole = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if gazole_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		replace wavg_price_gazole = wavg_price_gazole * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel p_rotterdam gazole_margin_17oclock wavg_price_gazole, by(id week week_n country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		gen log_p_wavg = log(wavg_price_gazole)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_5pm_sdid_20to100_coef = e(ATT)
		local diesel_5pm_sdid_20to100_se = e(se)
		
		sdid log_p_wavg id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_wavg_sdid_20to100_coef = e(ATT)
		local diesel_wavg_sdid_20to100_se = e(se)
		
		sdid log_p_5pm id week treated , covariates(de_brent) vce(bootstrap) reps(200) seed(10)
		local dsl_5pm_sdid_20to100_cr_coef = e(ATT)
		local dsl_5pm_sdid_20to100_cr_se = e(se)

		sdid gazole_margin_17oclock id week treated , vce(bootstrap) reps(200) seed(10)
		local dsl_marg_sdid_20to100_coef = e(ATT)
		local dsl_marg_sdid_20to100_se = e(se)
		
		local nr_obs_diesel_sdid_20to100 = _N
		
		sum gazole_margin_17oclock if country == "de" & treatment_period == 0
		local margin_diesel_20to100 = r(mean)	
		
	
	
	
	
	
	
	
	
		
///////////////////////////////////////////////////////////
////////// 20 to 40 km from Franco-German border //////////		
///////////////////////////////////////////////////////////

	
************************************************************
*****   Prepare data for estimation with SDID: petrol  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 40km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 40		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace e5_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_e5 = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if e5_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		replace wavg_price_e5 = wavg_price_e5 * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel p_rotterdam e5_margin_17oclock wavg_price_e5, by(id week week_n country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		gen log_p_wavg = log(wavg_price_e5)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local e5_5pm_sdid_20to40_coef = e(ATT)
		local e5_5pm_sdid_20to40_se = e(se)

		local nr_obs_e5_sdid_20to40 = _N
		
		
		
		

************************************************************
*****   Prepare data for estimation with SDID: diesel  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 40km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 40		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace gazole_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_gazole = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if gazole_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		replace wavg_price_gazole = wavg_price_gazole * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel p_rotterdam gazole_margin_17oclock wavg_price_gazole, by(id week week_n country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		gen log_p_wavg = log(wavg_price_gazole)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_5pm_sdid_20to40_coef = e(ATT)
		local diesel_5pm_sdid_20to40_se = e(se)
		
		local nr_obs_diesel_sdid_20to40 = _N
	
	
	
	
		
///////////////////////////////////////////////////////////
////////// 20 to 60 km from Franco-German border //////////		
///////////////////////////////////////////////////////////

	
************************************************************
*****   Prepare data for estimation with SDID: petrol  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 60km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 60		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace e5_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_e5 = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if e5_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		replace wavg_price_e5 = wavg_price_e5 * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel p_rotterdam e5_margin_17oclock wavg_price_e5, by(id week week_n country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		gen log_p_wavg = log(wavg_price_e5)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local e5_5pm_sdid_20to60_coef = e(ATT)
		local e5_5pm_sdid_20to60_se = e(se)
		
		local nr_obs_e5_sdid_20to60 = _N
		
		
		

************************************************************
*****   Prepare data for estimation with SDID: diesel  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 60km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 60		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace gazole_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_gazole = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if gazole_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		replace wavg_price_gazole = wavg_price_gazole * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel p_rotterdam gazole_margin_17oclock wavg_price_gazole, by(id week week_n country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		gen log_p_wavg = log(wavg_price_gazole)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_5pm_sdid_20to60_coef = e(ATT)
		local diesel_5pm_sdid_20to60_se = e(se)		
	
		local nr_obs_diesel_sdid_20to60 = _N
	
	
	
		
///////////////////////////////////////////////////////////
////////// 20 to 80 km from Franco-German border //////////		
///////////////////////////////////////////////////////////

	
************************************************************
*****   Prepare data for estimation with SDID: petrol  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 80km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 80		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace e5_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_e5 = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if e5_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		replace wavg_price_e5 = wavg_price_e5 * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel p_rotterdam e5_margin_17oclock wavg_price_e5, by(id week week_n country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		gen log_p_wavg = log(wavg_price_e5)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local e5_5pm_sdid_20to80_coef = e(ATT)
		local e5_5pm_sdid_20to80_se = e(se)
		
		local nr_obs_e5_sdid_20to80 = _N
		
		
		

************************************************************
*****   Prepare data for estimation with SDID: diesel  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 80km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 80		
			
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace gazole_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_gazole = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if gazole_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		replace wavg_price_gazole = wavg_price_gazole * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel p_rotterdam gazole_margin_17oclock wavg_price_gazole, by(id week week_n country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		gen log_p_wavg = log(wavg_price_gazole)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'
	
	** Regression analysis **
		sdid log_p_5pm id week treated , vce(bootstrap) reps(200) seed(10)
		local diesel_5pm_sdid_20to80_coef = e(ATT)
		local diesel_5pm_sdid_20to80_se = e(se)	
	
		local nr_obs_diesel_sdid_20to80 = _N
	

**************************
***** Export results *****	
**************************
	
	* Table 2: Main results
		clear
		set obs 5
		gen out_var = ""
		replace out_var = "Coefficient" if _n == 1
		replace out_var = "Standard error" if _n == 2
		replace out_var = "95% CI LB" if _n == 3
		replace out_var = "95% CI UB" if _n == 4
		replace out_var = "Observations" if _n == 5
		gen e5_all = .
		replace e5_all = round(`e5_5pm_sdid_all_coef', 0.001) if _n==1
		replace e5_all = round(`e5_5pm_sdid_all_se', 0.0001) if _n==2
		replace e5_all = round(`e5_5pm_sdid_all_coef' - 1.96 * `e5_5pm_sdid_all_se', 0.001) if _n==3
		replace e5_all = round(`e5_5pm_sdid_all_coef' + 1.96 * `e5_5pm_sdid_all_se', 0.001) if _n==4
		replace e5_all = `nr_obs_e5_sdid_all' if _n==5
		gen diesel_all = .
		replace diesel_all = round(`diesel_5pm_sdid_all_coef', 0.001) if _n==1
		replace diesel_all = round(`diesel_5pm_sdid_all_se', 0.0001) if _n==2
		replace diesel_all = round(`diesel_5pm_sdid_all_coef' - 1.96 * `diesel_5pm_sdid_all_se', 0.001) if _n==3
		replace diesel_all = round(`diesel_5pm_sdid_all_coef' + 1.96 * `diesel_5pm_sdid_all_se', 0.001) if _n==4
		replace diesel_all = `nr_obs_diesel_sdid_all' if _n==5
		gen e5_20to100 = .
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_coef', 0.001) if _n==1
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_se', 0.0001) if _n==2
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_coef' - 1.96 * `e5_5pm_sdid_20to100_se', 0.001) if _n==3
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_coef' + 1.96 * `e5_5pm_sdid_20to100_se', 0.001) if _n==4
		replace e5_20to100 = `nr_obs_e5_sdid_20to100' if _n==5
		gen diesel_20to100 = .
		replace diesel_20to100 = round(`diesel_5pm_sdid_20to100_coef', 0.001) if _n==1
		replace diesel_20to100 = round(`diesel_5pm_sdid_20to100_se', 0.0001) if _n==2
		replace diesel_20to100 = round(`diesel_5pm_sdid_20to100_coef' - 1.96 * `diesel_5pm_sdid_20to100_se', 0.001) if _n==3
		replace diesel_20to100 = round(`diesel_5pm_sdid_20to100_coef' + 1.96 * `diesel_5pm_sdid_20to100_se', 0.001) if _n==4
		replace diesel_20to100 = `nr_obs_diesel_sdid_20to100' if _n==5
	
		texsave using "$output\Table 2_main results.tex" , replace
	
	
	* Table C2: Weighted average prices
		clear
		set obs 5
		gen out_var = ""
		replace out_var = "Coefficient" if _n == 1
		replace out_var = "Standard error" if _n == 2
		replace out_var = "95% CI LB" if _n == 3
		replace out_var = "95% CI UB" if _n == 4
		replace out_var = "Observations" if _n == 5
		gen e5_all = .
		replace e5_all = round(`e5_wavg_sdid_all_coef', 0.001) if _n==1
		replace e5_all = round(`e5_wavg_sdid_all_se', 0.0001) if _n==2
		replace e5_all = round(`e5_wavg_sdid_all_coef' - 1.96 * `e5_wavg_sdid_all_se', 0.001) if _n==3
		replace e5_all = round(`e5_wavg_sdid_all_coef' + 1.96 * `e5_wavg_sdid_all_se', 0.001) if _n==4
		replace e5_all = `nr_obs_e5_sdid_all' if _n==5
		gen diesel_all = .
		replace diesel_all = round(`diesel_wavg_sdid_all_coef', 0.001) if _n==1
		replace diesel_all = round(`diesel_wavg_sdid_all_se', 0.0001) if _n==2
		replace diesel_all = round(`diesel_wavg_sdid_all_coef' - 1.96 * `diesel_wavg_sdid_all_se', 0.001) if _n==3
		replace diesel_all = round(`diesel_wavg_sdid_all_coef' + 1.96 * `diesel_wavg_sdid_all_se', 0.001) if _n==4
		replace diesel_all = `nr_obs_diesel_sdid_all' if _n==5
		gen e5_20to100 = .
		replace e5_20to100 = round(`e5_wavg_sdid_20to100_coef', 0.001) if _n==1
		replace e5_20to100 = round(`e5_wavg_sdid_20to100_se', 0.0001) if _n==2
		replace e5_20to100 = round(`e5_wavg_sdid_20to100_coef' - 1.96 * `e5_wavg_sdid_20to100_se', 0.001) if _n==3
		replace e5_20to100 = round(`e5_wavg_sdid_20to100_coef' + 1.96 * `e5_wavg_sdid_20to100_se', 0.001) if _n==4
		replace e5_20to100 = `nr_obs_e5_sdid_20to100' if _n==5
		gen diesel_20to100 = .
		replace diesel_20to100 = round(`diesel_wavg_sdid_20to100_coef', 0.001) if _n==1
		replace diesel_20to100 = round(`diesel_wavg_sdid_20to100_se', 0.0001) if _n==2
		replace diesel_20to100 = round(`diesel_wavg_sdid_20to100_coef' - 1.96 * `diesel_wavg_sdid_20to100_se', 0.001) if _n==3
		replace diesel_20to100 = round(`diesel_wavg_sdid_20to100_coef' + 1.96 * `diesel_wavg_sdid_20to100_se', 0.001) if _n==4
		replace diesel_20to100 = `nr_obs_diesel_sdid_20to100' if _n==5
	
		texsave using "$output\Table C2_wavgp.tex" , replace
	
	
	* Table C3: Alternative donuts
		clear
		set obs 5
		gen out_var = ""
		replace out_var = "Coefficient" if _n == 1
		replace out_var = "Standard error" if _n == 2
		replace out_var = "95% CI LB" if _n == 3
		replace out_var = "95% CI UB" if _n == 4
		replace out_var = "Observations" if _n == 5
		gen e5_20to40 = .
		replace e5_20to40 = round(`e5_5pm_sdid_20to40_coef', 0.001) if _n==1
		replace e5_20to40 = round(`e5_5pm_sdid_20to40_se', 0.0001) if _n==2
		replace e5_20to40 = round(`e5_5pm_sdid_20to40_coef' - 1.96 * `e5_5pm_sdid_20to40_se', 0.001) if _n==3
		replace e5_20to40 = round(`e5_5pm_sdid_20to40_coef' + 1.96 * `e5_5pm_sdid_20to40_se', 0.001) if _n==4
		replace e5_20to40 = `nr_obs_e5_sdid_20to40' if _n==5
		gen diesel_20to40 = .
		replace diesel_20to40 = round(`diesel_5pm_sdid_20to40_coef', 0.001) if _n==1
		replace diesel_20to40 = round(`diesel_5pm_sdid_20to40_se', 0.0001) if _n==2
		replace diesel_20to40 = round(`diesel_5pm_sdid_20to40_coef' - 1.96 * `diesel_5pm_sdid_20to40_se', 0.001) if _n==3
		replace diesel_20to40 = round(`diesel_5pm_sdid_20to40_coef' + 1.96 * `diesel_5pm_sdid_20to40_se', 0.001) if _n==4
		replace diesel_20to40 = `nr_obs_diesel_sdid_20to40' if _n==5
		gen e5_20to60 = .
		replace e5_20to60 = round(`e5_5pm_sdid_20to60_coef', 0.001) if _n==1
		replace e5_20to60 = round(`e5_5pm_sdid_20to60_se', 0.0001) if _n==2
		replace e5_20to60 = round(`e5_5pm_sdid_20to60_coef' - 1.96 * `e5_5pm_sdid_20to60_se', 0.001) if _n==3
		replace e5_20to60 = round(`e5_5pm_sdid_20to60_coef' + 1.96 * `e5_5pm_sdid_20to60_se', 0.001) if _n==4
		replace e5_20to60 = `nr_obs_e5_sdid_20to60' if _n==5
		gen diesel_20to60 = .
		replace diesel_20to60 = round(`diesel_5pm_sdid_20to60_coef', 0.001) if _n==1
		replace diesel_20to60 = round(`diesel_5pm_sdid_20to60_se', 0.0001) if _n==2
		replace diesel_20to60 = round(`diesel_5pm_sdid_20to60_coef' - 1.96 * `diesel_5pm_sdid_20to60_se', 0.001) if _n==3
		replace diesel_20to60 = round(`diesel_5pm_sdid_20to60_coef' + 1.96 * `diesel_5pm_sdid_20to60_se', 0.001) if _n==4
		replace diesel_20to60 = `nr_obs_diesel_sdid_20to60' if _n==5
		gen e5_20to80 = .
		replace e5_20to80 = round(`e5_5pm_sdid_20to80_coef', 0.001) if _n==1
		replace e5_20to80 = round(`e5_5pm_sdid_20to80_se', 0.0001) if _n==2
		replace e5_20to80 = round(`e5_5pm_sdid_20to80_coef' - 1.96 * `e5_5pm_sdid_20to80_se', 0.001) if _n==3
		replace e5_20to80 = round(`e5_5pm_sdid_20to80_coef' + 1.96 * `e5_5pm_sdid_20to80_se', 0.001) if _n==4
		replace e5_20to80 = `nr_obs_e5_sdid_20to80' if _n==5
		gen diesel_20to80 = .
		replace diesel_20to80 = round(`diesel_5pm_sdid_20to80_coef', 0.001) if _n==1
		replace diesel_20to80 = round(`diesel_5pm_sdid_20to80_se', 0.0001) if _n==2
		replace diesel_20to80 = round(`diesel_5pm_sdid_20to80_coef' - 1.96 * `diesel_5pm_sdid_20to80_se', 0.001) if _n==3
		replace diesel_20to80 = round(`diesel_5pm_sdid_20to80_coef' + 1.96 * `diesel_5pm_sdid_20to80_se', 0.001) if _n==4
		replace diesel_20to80 = `nr_obs_diesel_sdid_20to80' if _n==5
	
		texsave using "$output\Table C3_alternative donuts.tex" , replace
	
	
	* Table C4: Crude control
		clear
		set obs 5
		gen out_var = ""
		replace out_var = "Coefficient" if _n == 1
		replace out_var = "Standard error" if _n == 2
		replace out_var = "95% CI LB" if _n == 3
		replace out_var = "95% CI UB" if _n == 4
		replace out_var = "Observations" if _n == 5
		gen e5_all = .
		replace e5_all = round(`e5_5pm_sdid_all_crude_coef', 0.001) if _n==1
		replace e5_all = round(`e5_5pm_sdid_all_crude_se', 0.0001) if _n==2
		replace e5_all = round(`e5_5pm_sdid_all_crude_coef' - 1.96 * `e5_5pm_sdid_all_crude_se', 0.001) if _n==3
		replace e5_all = round(`e5_5pm_sdid_all_crude_coef' + 1.96 * `e5_5pm_sdid_all_crude_se', 0.001) if _n==4
		replace e5_all = `nr_obs_e5_sdid_all' if _n==5
		gen diesel_all = .
		replace diesel_all = round(`diesel_5pm_sdid_all_crude_coef', 0.001) if _n==1
		replace diesel_all = round(`diesel_5pm_sdid_all_crude_se', 0.0001) if _n==2
		replace diesel_all = round(`diesel_5pm_sdid_all_crude_coef' - 1.96 * `diesel_5pm_sdid_all_crude_se', 0.001) if _n==3
		replace diesel_all = round(`diesel_5pm_sdid_all_crude_coef' + 1.96 * `diesel_5pm_sdid_all_crude_se', 0.001) if _n==4
		replace diesel_all = `nr_obs_diesel_sdid_all' if _n==5
		gen e5_20to100 = .
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_crude_coef', 0.001) if _n==1
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_crude_se', 0.0001) if _n==2
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_crude_coef' - 1.96 * `e5_5pm_sdid_20to100_crude_se', 0.001) if _n==3
		replace e5_20to100 = round(`e5_5pm_sdid_20to100_crude_coef' + 1.96 * `e5_5pm_sdid_20to100_crude_se', 0.001) if _n==4
		replace e5_20to100 = `nr_obs_e5_sdid_20to100' if _n==5
		gen diesel_20to100 = .
		replace diesel_20to100 = round(`dsl_5pm_sdid_20to100_cr_coef', 0.001) if _n==1
		replace diesel_20to100 = round(`dsl_5pm_sdid_20to100_cr_se', 0.0001) if _n==2
		replace diesel_20to100 = round(`dsl_5pm_sdid_20to100_cr_coef' - 1.96 * `dsl_5pm_sdid_20to100_cr_se', 0.001) if _n==3
		replace diesel_20to100 = round(`dsl_5pm_sdid_20to100_cr_coef' + 1.96 * `dsl_5pm_sdid_20to100_cr_se', 0.001) if _n==4
		replace diesel_20to100 = `nr_obs_diesel_sdid_20to100' if _n==5
		
		texsave using "$output\Table C4_crude control.tex" , replace
		
	
	* Table C5: SDID with margins
		clear
		set obs 6
		gen out_var = ""
		replace out_var = "Coefficient" if _n == 1
		replace out_var = "Standard error" if _n == 2
		replace out_var = "95% CI LB" if _n == 3
		replace out_var = "95% CI UB" if _n == 4
		replace out_var = "Observations" if _n == 5
		replace out_var = "Mean retail margin" if _n == 6
		gen e5_all = .
		replace e5_all = round(`e5_margin_sdid_all_coef', 0.001) if _n==1
		replace e5_all = round(`e5_margin_sdid_all_se', 0.0001) if _n==2
		replace e5_all = round(`e5_margin_sdid_all_coef' - 1.96 * `e5_margin_sdid_all_se', 0.001) if _n==3
		replace e5_all = round(`e5_margin_sdid_all_coef' + 1.96 * `e5_margin_sdid_all_se', 0.001) if _n==4
		replace e5_all = `nr_obs_e5_sdid_all' if _n==5
		replace e5_all = round(`margin_e5_all', 0.01) if _n==6
		gen diesel_all = .
		replace diesel_all = round(`diesel_margin_sdid_all_coef', 0.001) if _n==1
		replace diesel_all = round(`diesel_margin_sdid_all_se', 0.0001) if _n==2
		replace diesel_all = round(`diesel_margin_sdid_all_coef' - 1.96 * `diesel_margin_sdid_all_se', 0.001) if _n==3
		replace diesel_all = round(`diesel_margin_sdid_all_coef' + 1.96 * `diesel_margin_sdid_all_se', 0.001) if _n==4
		replace diesel_all = `nr_obs_diesel_sdid_all' if _n==5
		replace diesel_all = round(`margin_diesel_all', 0.01) if _n==6
		gen e5_20to100 = .
		replace e5_20to100 = round(`e5_margin_sdid_20to100_coef', 0.001) if _n==1
		replace e5_20to100 = round(`e5_margin_sdid_20to100_se', 0.0001) if _n==2
		replace e5_20to100 = round(`e5_margin_sdid_20to100_coef' - 1.96 * `e5_margin_sdid_20to100_se', 0.001) if _n==3
		replace e5_20to100 = round(`e5_margin_sdid_20to100_coef' + 1.96 * `e5_margin_sdid_20to100_se', 0.001) if _n==4
		replace e5_20to100 = `nr_obs_e5_sdid_20to100' if _n==5
		replace e5_20to100 = round(`margin_e5_20to100', 0.01) if _n==6
		gen diesel_20to100 = .
		replace diesel_20to100 = round(`dsl_marg_sdid_20to100_coef', 0.001) if _n==1
		replace diesel_20to100 = round(`dsl_marg_sdid_20to100_se', 0.0001) if _n==2
		replace diesel_20to100 = round(`dsl_marg_sdid_20to100_coef' - 1.96 * `dsl_marg_sdid_20to100_se', 0.001) if _n==3
		replace diesel_20to100 = round(`dsl_marg_sdid_20to100_coef' + 1.96 * `dsl_marg_sdid_20to100_se', 0.001) if _n==4
		replace diesel_20to100 = `nr_obs_diesel_sdid_20to100' if _n==5
		replace diesel_20to100 = round(`margin_diesel_20to100', 0.01) if _n==6
	
		texsave using "$output\Table C5_margins.tex" , replace
	
	
	
	
	
	
	
	
	
	

	
		
//////////////////////////////////
////////// FULL COUNTRY //////////		
//////////////////////////////////

	
***********************************************************
*****   Prepare data for estimation with DID: petrol  *****
***********************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france.dta , clear

	* Keep only for time periods that are part of DID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing price
		drop if e5_17oclock_panel == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		
	* Gen numeric IDs for German stations, starting from 1 
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										

	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"		
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel , by(id date country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if date > date("20130912","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"
	
	** Regression analysis **
		eststo e5_5pm_did_all: reghdfe log_p_5pm treated  , ab(id date) cl(id)
	
		
		

***********************************************************
*****   Prepare data for estimation with DID: diesel  *****
***********************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france.dta , clear

	* Keep only for time periods that are part of DID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		
	* Drop if missing price
		drop if gazole_17oclock_panel == .

	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		
	* Gen numeric IDs for German stations, starting from 1
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel , by(id date country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if date > date("20130912","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	
	** Regression analysis **
		eststo diesel_5pm_did_all: reghdfe log_p_5pm treated  , ab(id date) cl(id)
	
	
	
	
		
////////////////////////////////////////////////////////////
////////// 20 to 100 km from Franco-German border //////////		
////////////////////////////////////////////////////////////

	
***********************************************************
*****   Prepare data for estimation with DID: petrol  *****
***********************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of DID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
		
	* Drop petrol stations that are less than 20km or more than 100km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 100		

	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing price
		drop if e5_17oclock_panel == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		
	* Gen numeric IDs for German stations, starting from 1 
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										

	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"		
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel , by(id date country)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if date > date("20130912","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"
		
	** Regression analysis **
		eststo e5_5pm_did_20to100: reghdfe log_p_5pm treated  , ab(id date) cl(id)
		
		

************************************************************
*****   Prepare data for estimation with DID: diesel  *****
************************************************************

// Baseline (1 day carryforward of prices for stations in Germany): weekly prices

	cd "$dta"
	use germany_france_border.dta , clear

	* Keep only for time periods that are part of DID analyses
			keep if date > d(12apr2013) & date < d(01apr2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)

	* Drop petrol stations that are less than 20km or more than 100km away from border
		keep if km_to_french_border > 20 & km_to_french_border < 100		
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		
	* Drop if missing price
		drop if gazole_17oclock_panel == .

	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		
	* Gen numeric IDs for German stations, starting from 1
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"										


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"					
		sum id2 if country=="fr"						
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel , by(id date country)
	
	* Gen log (gross) diesel price
		gen log_p_5pm = log(gazole_17oclock_panel)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if date > date("20130912","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	** Regression analysis **
		eststo diesel_5pm_did_20to100: reghdfe log_p_5pm treated  , ab(id date) cl(id)
	
	
		
	
	* Table C1
		esttab e5_5pm_did_all diesel_5pm_did_all e5_5pm_did_20to100 diesel_5pm_did_20to100 using "$output\Table C1_DID.tex" , b(4) se(5) ar2 replace booktabs keep(treated) star(* 0.10 ** 0.05 *** 0.01) label ///
		title(Effect of MPD on the logarithm of gross prices) ///
		nonumbers mtitles("(1) Gasoline" "(2) Diesel" "(3) Gasoline" "(4) Diesel") ///
		addnote("SEs are clustered at the fuel station level.")		
	
	
		

		
******************************************************************************************
**    Figure 8: Evolution of the difference in gross prices between Germany and France  **
******************************************************************************************

	* Use data set
		cd "$dta"
		use germany_france.dta , clear
			
	* Calculate average price over all stations for 17 o'clock
		gcollapse (mean) e5_17oclock_panel gazole_17oclock_panel, by(date country)

		sort country date
		
	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)	
		
	* Drop German prices before 15 Apr 2013
		drop if date < d(15apr2013)

	* Rename
		rename e5_17oclock_panel e5_price_17oclock
		rename gazole_17oclock_panel gazole_price_17oclock
		
	* Reshape
		reshape wide e5_price_17oclock gazole_price_17oclock, i(date) j(country) string
		
	* Gen avg gross price in pre-treatment period for FR and DE
		gen pre_treatment = date<d(12sep2013)
		
		egen avg_price_petrolde = mean(e5_price_17oclockde) if pre_treatment==1
		egen avg_price_petrolfr = mean(e5_price_17oclockfr) if pre_treatment==1
		egen avg_price_dieselde = mean(gazole_price_17oclockde) if pre_treatment==1
		egen avg_price_dieselfr = mean(gazole_price_17oclockfr) if pre_treatment==1
				
	* Fill in missing values for gross price
		foreach x in avg_price_petrolde avg_price_petrolfr avg_price_dieselde avg_price_dieselfr {
			replace `x'=0 if `x'==.
			gegen `x'_m=max(`x') 
			replace `x'=`x'_m 
			drop `x'_m 
		}
	
	* Gen demeaned gross price
		foreach v in price {
			gen demean_`v'_e5_de = e5_`v'_17oclockde - avg_`v'_petrolde
			gen demean_`v'_e5_fr = e5_`v'_17oclockfr - avg_`v'_petrolfr
			gen demean_`v'_diesel_de = gazole_`v'_17oclockde - avg_`v'_dieselde
			gen demean_`v'_diesel_fr = gazole_`v'_17oclockfr - avg_`v'_dieselfr
		}
		
	* Gen differences in gross prices b/w DE and FR
		gen diff_price_petrol = demean_price_e5_de - demean_price_e5_fr 
		gen diff_price_diesel = demean_price_diesel_de - demean_price_diesel_fr 
		
		
	* Replace to missing values for Germany between 12 September 2013 and 01 October 2013
		replace diff_price_petrol = . if date > d(12sep2013) & date < d(01oct2013)
		replace diff_price_diesel = . if date > d(12sep2013) & date < d(01oct2013)
		
	
	* Gen Figure 8: Evolution of the difference in gross prices between Germany and France
	twoway (line diff_price_diesel date if date>= d(15apr2013) & date<d(01sep2014), lpattern(solid)   cmissing(n)) ///
			(line diff_price_petrol date if date>=d(15apr2013) & date<d(01sep2014), lpattern(dash)  cmissing(n)) ///
			, /*title("Evolution of retail margins")*/  ytitle("Difference in gross price at 5 pm, DE vs FR", size(medium)) ///
			legend(label(1 "Diesel") label(2 "Gasoline") rows(1) rowgap(*.2) symx(*1) size(medsmall)) xline(`=d(12sep2013)', lcolor(gs0) lwidth(medium)) ///
			xtitle("") xlabel( `=d(01may2013)' "1 May 2013" `=d(01aug2013)' "1 August 2013" `=d(01nov2013)' "1 November 2013" `=d(01feb2014)' "1 February 2014" `=d(01may2014)' "1 May 2014" `=d(01aug2014)' "1 August 2014", labs(medsmall)) ///
			ylabel(, grid labs(medsmall)) bgcolor(white)  /*xline(`=d(01dec2013)', lcolor(gs0) lwidth(medium) lpattern(dash))*/ yline(0, lcolor(gs0) lwidth(medium)) scale(1.2)	ysize(2.2) xsize(6)	
	
	graph export "$output\Figure_9_diff_price_de_fr_color.pdf", replace
	
	
	* PDF Format for JPE Micro
	twoway (line diff_price_diesel date if date>= d(15apr2013) & date<d(01sep2014), lpattern(solid) cmissing(n) lcolor(black)) ///
			(line diff_price_petrol date if date>=d(15apr2013) & date<d(01sep2014), lpattern(dash)  cmissing(n) lcolor(gs0)) ///
			,  ytitle("Difference in gross price at 5 pm, DE vs FR") ///
			legend(label(1 "Diesel") label(2 "Gasoline") rows(1) rowgap(*.2) symx(*1)) xline(`=d(12sep2013)', lcolor(gs0) lwidth(medium)) ///
			xtitle("") xlabel( `=d(01may2013)' "1 May 2013" `=d(01aug2013)' "1 August 2013" `=d(01nov2013)' "1 November 2013" `=d(01feb2014)' "1 February 2014" `=d(01may2014)' "1 May 2014" `=d(01aug2014)' "1 August 2014") ///
			ylabel(, grid ) bgcolor(white) yline(0, lcolor(gs0) lwidth(medium)) scale(1) ysize(6) xsize(9)	
	
	graph export "$output\Figure_8_diff_price_de_fr_bw.pdf", replace
	
	
	

//////////////////////////////////
////////// FULL COUNTRY //////////		
//////////////////////////////////

	
************************************************************
*****   Prepare data for estimation with SDID: petrol  *****
************************************************************


	cd "$dta"
	use germany_france.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01sep2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
	
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace e5_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace e5_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_e5 = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if e5_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace e5_17oclock_panel = e5_17oclock_panel * 100
		replace wavg_price_e5 = wavg_price_e5 * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) e5_17oclock_panel p_rotterdam e5_margin_17oclock wavg_price_e5, by(id week week_n country date)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(e5_17oclock_panel)
		gen log_p_wavg = log(wavg_price_e5)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	//    Monthly   //

		gen month = 1 if date<d(01may2013)
		replace month = 2 if date<d(01jun2013) & date>=d(01may2013)
		replace month = 3 if date<d(01jul2013) & date>=d(01jun2013)
		replace month = 4 if date<d(01aug2013) & date>=d(01jul2013)
		replace month = 5 if date<d(12sep2013) & date>=d(01aug2013)
		replace month = 6 if date<d(13sep2013) & date>=d(01sep2013)				// this only includes 1-12 Sep 2013, as data for 13-30 Sep 2013 is missing
		replace month = 7 if date<d(01nov2013) & date>=d(13sep2013)				// this is Oct 2013. Rest of Sept 2013 is missing
		replace month = 8 if date<d(01dec2013) & date>=d(01nov2013)
		replace month = 9 if date<d(01jan2014) & date>=d(01dec2013)
		replace month = 10 if date<d(01feb2014) & date>=d(01jan2014)
		replace month = 11 if date<d(01mar2014) & date>=d(01feb2014)
		replace month = 12 if date<d(01apr2014) & date>=d(01mar2014)
		replace month = 13 if date<d(01may2014) & date>=d(01apr2014)
		replace month = 14 if date<d(01jun2014) & date>=d(01may2014)
		replace month = 15 if date<d(01jul2014) & date>=d(01jun2014)
		replace month = 16 if date<d(01aug2014) & date>=d(01jul2014)
		replace month = 17 if date<d(01sep2014) & date>=d(01aug2014)

		tostring id , g(id_string)
		
		collapse (mean) log_p_5pm treated , by(id_string month)		
		
		ren id_string id
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'

		
	** Regression analysis **
		sdid log_p_5pm id month treated , vce(noinference) graph  graph_export(groups, .pdf)
		
		
		
matrix lambda = e(lambda)[1..6,1] //save lambda weight
matrix yco = e(series)[1..6,2] //control baseline
matrix ytr = e(series)[1..6,3] //treated baseline
matrix aux = lambda'*(ytr - yco) //calculate the pre-treatment mean
scalar meanpre_o = aux[1,1]
matrix difference = e(difference)[1..17,1..2] // Store Ytr-Yco
svmat difference
ren (difference1 difference2) (time d)
replace d = d - meanpre_o // Calculate vector in (8)
		

local B = 200
local b = 1
while `b'<=`B' {
	preserve
		bsample, cluster(id) idcluster(c2)
		count if treated == 0
		local r1 = r(N)
		count if treated != 0
		local r2 = r(N)
		if (`r1'!=0 & `r2'!=0) {
			qui sdid log_p_5pm c2 month treated , vce(noinference) graph 
			matrix lambda_b = e(lambda)[1..6,1] //save lambda weight
			matrix yco_b = e(series)[1..6,2] //control baseline
			matrix ytr_b = e(series)[1..6,3] //treated baseline
			matrix aux_b = lambda_b'*(ytr_b - yco_b) //calculate the pre-treatment mean
			matrix meanpre_b = J(17,1,aux_b[1,1])
			matrix d`b' = e(difference)[1..17,2] - meanpre_b
			local ++b
		}
	restore
}


local B = 200
local b = 1
preserve
	keep time d
	keep if time!=.
	forval b=1/`B'{
		svmat d`b' // import each bootstrap replicate of difference between trends
	}
	egen rsd = rowsd(d11 - d`B'1) //calculate standard deviation of this difference
	gen LCI = d + invnormal(0.025)*rsd //lower bounds on bootstrap CIs
	gen UCI = d + invnormal(0.975)*rsd //upper bounds on bootstrap CIs
	ren (UCI LCI d) (UCI_e5 LCI_e5 d_e5)
	keep UCI_e5 LCI_e5 time d_e5
	save "$dta/gasoline_data.dta" , replace
	
restore		



	
************************************************************
*****   Prepare data for estimation with SDID: diesel  *****
************************************************************


	cd "$dta"
	use germany_france.dta , clear

	* Keep only for time periods that are part of SDID analyses
			keep if date > d(12apr2013) & date < d(01sep2014)

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
	
	* Gen dummies for weeks
		gen week = date - dow(date) 
		format week %td 
		egen week_n = group(week)

	* Re-check week dummy for start of the treatment
		tab week if date==d(12sep2013)											// week of 8 Sep 2013, week_n = 22
		tab week_n if date==d(12sep2013)	
		tab date if week==d(08sep2013)
		
	* Re-classify 12 & 13 Sep 2013 into the next week (to keep pre vs post-treated weeks separate)
		replace week_n = 23 if date==d(12sep2013)|date==d(13sep2013)
		replace week = d(15sep2013) if date==d(12sep2013)|date==d(13sep2013)
		
	* Replace all prices and retail margins between 12 September 2013 and 01 October 2013 as missing
		replace gazole_17oclock_panel = . if date > d(12sep2013) & date < d(01oct2013)
		replace gazole_margin_17oclock = . if date > d(12sep2013) & date < d(01oct2013)
		replace wavg_price_gazole = . if date > d(12sep2013) & date < d(01oct2013)

	* Drop if missing margin (missing price <-> missing margin)
		drop if gazole_margin_17oclock == .
			
	* Convert input and output prices to Eurocent/litre
		replace gazole_17oclock_panel = gazole_17oclock_panel * 100
		replace wavg_price_gazole = wavg_price_gazole * 100
		replace p_rotterdam = p_rotterdam * 100
		
	* Gen numeric IDs for German stations, starting from 1 [s.th. French station are first in the list for estimation with SDID]
		egen id1=group(station_id) if country=="de"
		sum id1 if country=="de"														// station ids in the range of [1; 14449] for Germany


	* Replace numeric IDs with 0 if French station
		replace id1=0 if country=="fr"

	* Gen numeric IDs for French stations, starting from 1
		egen id2=group(station_id) if country=="fr"
		replace id2=0 if country =="de"													// replace to 0 for German stations
		sum id2 if country=="fr"														// station id in the range of [1; 6681] for France
		local max_id_fr = r(max)

	* Replace German IDs to id+max_id_fr to create a single station id
		replace id1 = id1 + `max_id_fr' if country=="de"

	* Gen a single station id
		gen id=id1+id2
		drop id1 id2

	* Set panel structure	
		xtset id date

		gen country_2 = 0
		replace country_2 = 1 if country == "de"
		label var country_2 "Germany dummy"
		label var p_rotterdam "Oil price"
		
	* Drop unnecessary variables
		drop station_id state
		
	* Don't have price data in that time window
		drop if date > d(12sep2013) & date < d(01oct2013)
		
		
	* Collapse at weekly x station level
		gcollapse (mean) gazole_17oclock_panel p_rotterdam gazole_margin_17oclock wavg_price_gazole, by(id week week_n country date)
	
	* Gen log (gross) E5 price
		gen log_p_5pm = log(gazole_17oclock_panel)
		gen log_p_wavg = log(wavg_price_gazole)
		
		
	* Generate treatment variable
		gen treatment_group = 0
		replace treatment_group = 1 if country == "de"
		gen treatment_period = 0
		replace treatment_period = 1 if week >= date("20130916","YMD")

	* Define treatment variable
		gen treated = 0
		replace treated = 1 if treatment_group == 1 & treatment_period == 1
		label var treated "MPD"

	* Gen interaction with crude oil price
		gen de_brent = treatment_group*p_rotterdam
		
	//    Monthly   //

		gen month = 1 if date<d(01may2013)
		replace month = 2 if date<d(01jun2013) & date>=d(01may2013)
		replace month = 3 if date<d(01jul2013) & date>=d(01jun2013)
		replace month = 4 if date<d(01aug2013) & date>=d(01jul2013)
		replace month = 5 if date<d(12sep2013) & date>=d(01aug2013)
		replace month = 6 if date<d(13sep2013) & date>=d(01sep2013)				// this only includes 1-12 Sep 2013, as data for 13-30 Sep 2013 is missing
		replace month = 7 if date<d(01nov2013) & date>=d(13sep2013)				// this is Oct 2013. Rest of Sept 2013 is missing
		replace month = 8 if date<d(01dec2013) & date>=d(01nov2013)
		replace month = 9 if date<d(01jan2014) & date>=d(01dec2013)
		replace month = 10 if date<d(01feb2014) & date>=d(01jan2014)
		replace month = 11 if date<d(01mar2014) & date>=d(01feb2014)
		replace month = 12 if date<d(01apr2014) & date>=d(01mar2014)
		replace month = 13 if date<d(01may2014) & date>=d(01apr2014)
		replace month = 14 if date<d(01jun2014) & date>=d(01may2014)
		replace month = 15 if date<d(01jul2014) & date>=d(01jun2014)
		replace month = 16 if date<d(01aug2014) & date>=d(01jul2014)
		replace month = 17 if date<d(01sep2014) & date>=d(01aug2014)

*		tab month, gen(month_n)

		tostring id , g(id_string)
		
		collapse (mean) log_p_5pm treated , by(id_string month)		
		
*		gen zero=0
		
		ren id_string id
		
	* Generate a balanced sample	
		bysort id: gen count_id_obs = _N
		su count_id_obs , det
		local max_id_obs = r(max)
		keep if count_id_obs == `max_id_obs'

		
	** Regression analysis **
		sdid log_p_5pm id month treated , vce(noinference) graph  graph_export(groups, .pdf)
		
		
		
matrix lambda = e(lambda)[1..6,1] //save lambda weight
matrix yco = e(series)[1..6,2] //control baseline
matrix ytr = e(series)[1..6,3] //treated baseline
matrix aux = lambda'*(ytr - yco) //calculate the pre-treatment mean
scalar meanpre_o = aux[1,1]
matrix difference = e(difference)[1..17,1..2] // Store Ytr-Yco
svmat difference
ren (difference1 difference2) (time d)
replace d = d - meanpre_o // Calculate vector in (8)
		

local B = 200
local b = 1
while `b'<=`B' {
	preserve
		bsample, cluster(id) idcluster(c2)
		count if treated == 0
		local r1 = r(N)
		count if treated != 0
		local r2 = r(N)
		if (`r1'!=0 & `r2'!=0) {
			qui sdid log_p_5pm c2 month treated , vce(noinference) graph 
			matrix lambda_b = e(lambda)[1..6,1] //save lambda weight
			matrix yco_b = e(series)[1..6,2] //control baseline
			matrix ytr_b = e(series)[1..6,3] //treated baseline
			matrix aux_b = lambda_b'*(ytr_b - yco_b) //calculate the pre-treatment mean
			matrix meanpre_b = J(17,1,aux_b[1,1])
			matrix d`b' = e(difference)[1..17,2] - meanpre_b
			local ++b
		}
	restore
}


local B = 200
local b = 1
preserve
	keep time d
	keep if time!=.
	forval b=1/`B'{
		svmat d`b' // import each bootstrap replicate of difference between trends
	}
	egen rsd = rowsd(d11 - d`B'1) //calculate standard deviation of this difference
	gen LCI = d + invnormal(0.025)*rsd //lower bounds on bootstrap CIs
	gen UCI = d + invnormal(0.975)*rsd //upper bounds on bootstrap CIs
	ren (UCI LCI d) (UCI_diesel LCI_diesel d_diesel)
	keep UCI_diesel LCI_diesel time d_diesel
	save "$dta/diesel_data.dta" , replace
	
restore		



** Figure 10

use "$dta/gasoline_data.dta" , clear
merge 1:1 time using "$dta/diesel_data.dta"
drop _m

	
tw (rcap UCI_e5 LCI_e5 time, color(red) lpattern(solid)) ///
   (line d_e5 time, color(red) lpattern(dash)) ///
   (rcap UCI_diesel LCI_diesel time, color(green) lpattern(solid)) ///
   (line d_diesel time, color(green)) ///
   (scatter d_e5 time, color(red) msymbol(t)) ///
   (scatter d_diesel time, color(green) msymbol(d)), ///
   xtitle("") ytitle("Logarithm of 5pm prices") ///
   legend(order(6 "Diesel" 5 "Gasoline") rows(1) rowgap(*.2) symx(*1) size(medsmall)) ///
   xline(6.5, lc(black) lw(medium)) ///
   xlabel(1 "Apr 2013" 2 "May" 3 "Jun" 4 "Jul" 5 "Aug" 6 "1-11 Sep" 7 "Oct" 8 "Nov" 9 "Dec" 10 "Jan 2014" 11 "Feb" 12 "Mar" 13 "Apr" 14 "May" 15 "Jun" 16 "Jul" 17 "Aug", labs(small)) ///
 	ylabel(, grid labs(medsmall)) bgcolor(white) yline(0, lcolor(gs0) lwidth(medium)) scale(1.2)	ysize(2.5) xsize(5)	

	graph export "$output/Figure 10_SDID Event Study_color.pdf", replace
	
	
	* PDF Format for JPE Micro
tw (rcap UCI_e5 LCI_e5 time, color(black) lpattern(solid)) ///
   (line d_e5 time, color(black) lpattern(dash)) ///
   (rcap UCI_diesel LCI_diesel time, color(gs0) lpattern(solid)) ///
   (line d_diesel time, color(gs0)) ///
   (scatter d_e5 time, color(black) msymbol(t)) ///
   (scatter d_diesel time, color(gs0) msymbol(d)), ///
   xtitle("") ytitle("Logarithm of 5pm prices") ///
   legend(order(6 "Diesel" 5 "Gasoline") rows(1) rowgap(*.2) symx(*1) ) ///
   xline(6.5, lc(black) lw(medium)) ///
   xlabel(1 "Apr 2013" 3 "Jun" 5 "Aug" 7 "Oct" 9 "Dec" 11 "Feb 2014" 13 "Apr" 15 "Jun" 17 "Aug") ///
 	ylabel(, grid ) bgcolor(white) yline(0, lcolor(gs0) lwidth(medium)) scale(1)	ysize(6) xsize(9)	

	graph export "$output/Figure 10_SDID Event Study_bw.pdf", replace	
	
	
	
	
	
	
	